package sky.treasure.results;

import sky.treasure.Cell;
import sky.treasure.FindPathCoordinator;
import sky.treasure.ICoordinator;
import sky.treasure.ITreasureHunter;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 14.01.14
 * Time: 23:52
 * To change this template use File | Settings | File Templates.
 */
public class CannotMove implements IResult {

    @Override
    public IResult make(ITreasureHunter hunter, Cell cell) {
        ICoordinator coordinator = hunter.getCoordinator();
        Cell tempCell = coordinator.getNextCell(cell.getCoordinates());
        IResult result = hunter.analyzeCell(cell);
        while(result.getClass()==this.getClass()) {
            if (result.getClass()==EndOfAlgorithm.class) {
                return result;
            }
            tempCell = coordinator.getNextCell(tempCell.getCoordinates());
            result = hunter.analyzeCell(cell);
        }
        hunter.addCoordinator(coordinator);
        hunter.setCoordinator(new FindPathCoordinator(coordinator.getArea(), tempCell.getCoordinates()));
        cell = hunter.getCoordinator().getNextCell(hunter.getCoordinates());
        hunter.move(cell);
        return new Result();
    }
}
